package com.p7.framework.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.p7.framework.common.exception.RequestParamException;
import com.p7.framework.service.HomeService;

/**
 * @ClassName: HomeServiceImpl
 * @Description: HomeServiceImpl
 * @author 杨振
 * @date 2017年12月13日 下午3:46:28
 * @Copyright: 2017
 **/
@Service
public class HomeServiceImpl implements HomeService {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	public List<Map<String, Object>> getAll() {
		return jdbcTemplate.queryForList("select * from home ");
	}

	@Transactional
	@Override
	public void doInsert() {
		jdbcTemplate.execute("insert into home(name,owner) values('我的小屋','张三');");
		throw new RequestParamException("system.error");
	}

	public String home(String homeName) {

		if (StringUtils.isBlank(homeName)) {
			throw new RequestParamException("homeName_is_blank");
		}

		System.out.println(homeName + "'s home");

		return homeName + "'s home";
	}
}
